home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
3_14.lha
/
3_14
/
3_14e.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
1KB
|
50 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ Interpret the function whose definition
/ is stored in the string funcdefn, using the
/ arguments newargs.
ifdef STRSTREAM
include <strstream.h>
endif
ouble interpfunc(double *newargs, char *funcdefn)
/cerr << "interpfunc(" << funcdefn << ")\n"; /* DELETE */
// save old values
istream savecin = cin;
token_value savecurr_tok = curr_tok;
double *saveargs = curfuncargs;
// set new values
ifdef STRSTREAM
strstreambuf str(strlen(funcdefn), funcdefn);
istream ncin(&str);
cin = ncin;
else
istream *ncin = new istream(strlen(funcdefn), funcdefn);
cin = *ncin;
endif
curfuncargs = newargs;
// interpret the string
double val = 0;
while (cin)
{
get_token();
if (curr_tok == END) break;
if (curr_tok == PRINT) continue;
val = expr();
}
/cerr << "interpfunc() returns " << val << "\n"; /* DELETE */
// restore the old values
ifndef STRSTREAM
delete ncin;
endif
curfuncargs = saveargs;
curr_tok = savecurr_tok;
cin = savecin;
return val;